package com.songjg.demo.controller;

import com.alibaba.druid.support.json.JSONUtils;
import com.github.pagehelper.util.StringUtil;
import com.songjg.demo.enums.ResultCode;
import com.songjg.demo.interfaces.AutoIdempotent;
import com.songjg.demo.token.TokenServie;
import com.songjg.demo.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@RestController
public class TokenDemo {

    @Resource
    private TokenServie tokenServie;
    @PostMapping("/token/create")
    public ResponseResult createToken(){
        String token = tokenServie.createToken();
        if (StringUtil.isNotEmpty(token)) {
            return new ResponseResult(ResultCode.OK.getCode(),ResultCode.OK.getMsg(),token);
        }
        return ResponseResult.error();
    }

    @AutoIdempotent
    @PostMapping("/token/testIdempotence")
    public ResponseResult testIdempotence() {
        return ResponseResult.ok();
    }
}
